/* Plot each DGP's CEF.
*/

clear
set more off
set scheme  s1mono 

cap log close
log using "${logs}/dgp_cefs.log", replace	

* RDD
local count = 1
foreach dgp in "ADGP1" "BDGP2" "CDGP3" "DDGP4" "EDGP5" "FDGP6" "GDGP7" "HDGP8" "IDGP9" "JDGP10" "KDGP11" {

use "${dat}/DGP/`dgp'_Coefficients.dta", clear
rename x x1
gen rhs = 0
replace rhs = 1 if _n == 2
tempfile coefs
save `coefs', replace

use "${dat}/DGP/`dgp'_ScaledRunningVariable.dta", clear
gen rhs = x >= 0

merge m:1 rhs using `coefs'

gen cef = cst + x * x1 + x^2 * x2 + x^3 * x3 + x^4 * x4 + x^5 * x5

sort x
twoway line cef x if x < 0, color(gs6) || line cef x if x >= 0, color(gs6) ///
	xtitle(x) ytitle(y) legend(off) name(graph`count', replace) 
local count = `count' + 1

}


graph combine graph1 graph2 graph3 graph4 graph5 graph6 graph7 graph8 graph9 graph10 graph11
graph export "${output}/cef-rdd-combined.pdf", as(pdf) replace

graph close _all

log close
